@extends('admin')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="/">首页</a>
                <i class="icon-double-angle-right"></i>
                <span>颜色</span>
            </li>

        </ul><!-- .breadcrumb -->

        <!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <div class="row">
                <div class="col-xs-12">
                    <a class="btn btn-success" href="color-create.html">添加颜色</a>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->


                <div class="alert alert-block hidden">
                    <button type="button" class="close" data-dismiss="alert">
                        <i class="icon-remove"></i>
                    </button>

                    <i class="icon-tip"></i>
                    <strong class=""></strong>
                </div>

                <hr>

                <div class="row">
                    <div class="col-xs-12">
                        <h3 class="header smaller lighter blue">颜色列表</h3>
                        <div class="table-header hidden">
                            颜色搜索结果
                        </div>

                        <div class="table-responsive">
                            <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="center">
                                        <label>
                                            <input type="checkbox" class="ace" />
                                            <span class="lbl"></span>
                                        </label>
                                    </th>
                                    <th>颜色名称</th>
                                    <th>简称</th>
                                    <th></th>
                                </tr>
                                </thead>

                                <tbody>
                                @if(count($colorList) === 0)
                                    <tr class="odd">
                                        <td colspan="4" class="text-center">暂无数据</td>
                                    </tr>
                                @endif
                                @foreach($colorList as $key => $color)
                                    <tr class="{{ $key % 2 === 0 ? 'odd' : 'even' }}">
                                        <td class="center">
                                            <label>
                                                <input type="checkbox" class="ace" value="{{ $color->id }}" />
                                                <span class="lbl"></span>
                                            </label>
                                        </td>

                                        <td>
                                            <span>{{ $color->title }}</span>
                                        </td>

                                        <td>
                                            <span>{{ $color->short }}</span>
                                        </td>

                                        <td>
                                            <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                                <a class="green" href="color-update-{{ $color->id }}.html">
                                                    <i class="icon-pencil bigger-130"></i>
                                                </a>

                                                <a class="red delete-color" data-id="{{ $color->id }}" href="#">
                                                    <i class="icon-trash bigger-130"></i>
                                                </a>
                                            </div>

                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

            </div><!-- /.col -->
        </div>
    </div><!-- /.page-content -->
@endsection
@section('custom-script')
    <script type="text/javascript">
        jQuery(function($) {

            $('table th input:checkbox').on('click' , function(){
                        var that = this;
                        $(this).closest('table').find('tr > td:first-child input:checkbox')
                                .each(function(){
                                    this.checked = that.checked;
                                    $(this).closest('tr').toggleClass('selected');
                                });

                    });


            $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
            function tooltip_placement(context, source) {
                var $source = $(source);
                var $parent = $source.closest('table')
                var off1 = $parent.offset();
                var w1 = $parent.width();

                var off2 = $source.offset();
                var w2 = $source.width();

                if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
                return 'left';
            }

            $('.delete-color').click(function(){
                var tr = $(this).parents('tr');
                var url = 'color-delete.html';
                var id = $(this).attr('data-id');
                $.post(url, {id:id}, function(e){
                    if (e.body.status === 200) {
                        $('.alert-block').removeClass('hidden').addClass('alert-success');
                        $('.alert-block i.icon-tip').removeClass('icon-remove').addClass('icon-ok');
                        tr.remove();
                    } else {
                        $('.alert-block').removeClass('hidden').addClass('alert-danger');
                        $('.alert-block i.icon-tip').removeClass('icon-ok').addClass('icon-remove');
                    }
                    $('.alert-block strong').text(e.body.msg);
                });
            });
        });
    </script>
@endsection